<template>
	<view class="content">
		<view class="headerImg" @click="uploadImg">
			<image v-if="logoInfo.url!=''" :src="logoInfo.url"></image>
			<image v-if="logoInfo.url==''" src="http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/mingmei/smallicon/icon/default.png"></image>
			<view style="color: #666666;">点击更换企业logo</view>
		</view>
		<view class="catList">
			<catLabel dataType="text" text="姓名"  v-model="realName"/>
			<catLabel dataType="text" inputType="number" text="手机"  v-model="phone"/>
			<catLabel dataType="text" text="职位"  v-model="position"/>
			<catLabel dataType="text" text="邮箱"  v-model="email"/>
			<catLabel dataType="text" text="企业名称"  v-model="companyname"/>
			<catLabel dataType="text" text="企业简称"  v-model="encompanyname"/>
			<catLabel dataType="text" text="企业地址"  v-model="address"/>
			<catLabel dataType="text" text="网站"  v-model="website"/>
		</view>
		<button class="submit" @click="setCompanyCardData">提交</button>
	</view>
</template>

<script>
	import catLabel from "@/components/cat-label/cat-label.vue"
	export default{
		data(){
			return{
				realName: '',
				phone: '',
				position: '',
				email: '',
				companyname: '',
				encompanyname: '',
				address: '',
				website: '',
				logoInfo: {
					id: '',
					url: ''
				}
			}
		},
		components:{
			catLabel
		},
		onLoad(options) {
			if (options.userId) {
				this.userId = options.userId;
			}
		},
		onShow(){
			this.getCompanyCardData();
		},
		methods: {
			//设置企业名片
			async setCompanyCardData(){
				let userToken=uni.getStorageSync('userToken');
				let params = {
					user_token: userToken,
					user_name: this.realName,
					phone: this.phone,
					position: this.position,
					email: this.email,
					company_name: this.companyname,
					en_company_name: this.encompanyname,
					address: this.address,
					website: this.website,
					logo_id: this.logoInfo.id
				}
				
				const res=await this.$api.setCompanyCardData(params);
				uni.showToast({
					icon:'none',
					title:res.data.message
				})
				if(res.data.level=='success'){
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},2000)
				}
			},
			async getCompanyCardData(){
				let userToken = uni.getStorageSync('userToken');
				let res = await this.$api.getCompanyCardData({
					user_token: userToken
				})
				if (res.data.level == 'success') {
					let data = res.data.data;
					this.realName = data.user_name;
					this.phone = data.phone;
					this.position = data.position;
					this.email = data.email;
					this.companyname = data.company_name;
					this.encompanyname = data.en_company_name;
					this.address = data.address;
					this.website = data.website;
					this.logoInfo.id = data.logo_id;
					this.logoInfo.url = data.logo_url;
				}
			},
			async uploadImg() {
				//上传头像
				let res = await this.$currency.upLoadImage()
				let data = JSON.parse(res.data)
				if (data.level != 'success') {
					uni.showToast({
						title: data.message,
						icon: 'none'
					})
					return
				}
				this.logoInfo = {
					url: data.data.img_url,
					id: data.data.id
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.headerImg{
		text-align: center;
		padding: 30rpx;
		image{
			width: 200rpx;
			height: 200rpx;
			border-radius: 360rpx;
			overflow: hidden;
		}
	}
	.catList{
		padding-bottom:100rpx;
	}
	.submit{
		position: fixed;
		bottom:0rpx;
		width: 100%;
		background: linear-gradient(-135deg, #57D1E2 0%, #37AED6 100%);
		color:#fff
	}
</style>